package com.zhkj.txg.module.member.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.member.entity.MemberListProductEntity
import com.zhkj.txg.module.member.ui.MemberProductActivity
import com.zhkj.txg.utils.ImageUtils

class MemberProductAdapter :
    BaseQuickAdapter<MemberListProductEntity, BaseViewHolder>(R.layout.item_member_goods),
    LoadMoreModule {

    init {
        setOnItemClickListener { _, _, position ->
            val entity = data[position]
            MemberProductActivity.start(context, entity.id.toLong())
        }
    }

    override fun convert(helper: BaseViewHolder, item: MemberListProductEntity) {
        with(item) {
            val imageView = helper.setText(R.id.tvGoodsTitle, goodsName)
                .setText(R.id.tvGoodsPrice, SpanUtil.setMoneySymbol(price))
                .setVisible(R.id.tvGoodsTag, android.text.TextUtils.equals(isNew, "1"))
                .getView<ImageView>(R.id.ivGoodsThumb)
            ImageUtils.loadImage(context, imageView, item.image)

            with(helper.getView<TextView>(R.id.tvSellSpread)) {
                paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
                text = SpanUtil.setMoneySymbol(marketPrice)
            }
        }
    }
}